package com.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * TestController
 *
 * @author zhouxianfeng
 * @date 2021-6-1
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private Source source;

    private AtomicInteger index = new AtomicInteger(0);

    @GetMapping
    public void test() {
        source.output().send(MessageBuilder.withPayload("test-transaction-" + index.incrementAndGet()).build());
        log.info(" prepare 消息发送成功");
    }

}
